package gatperdut.chato.lucene.indexer.mechanisms;

import gatperdut.chato.constants.CSConstantsLucene;
import gatperdut.chato.lucene.indexer.CMIndexer;
import gatperdut.chato.lucene.parser.CMParser;
import gatperdut.chato.lucene.parser.mechanisms.MechanismsParser;
import gatperdut.chato.lucene.parseresult.mechanisms.MechanismParseResult;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.xml.stream.XMLStreamException;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;

public class MechanismsIndexer extends CMIndexer {

    public MechanismsIndexer( IndexWriter writer ) throws IOException {
        super( writer );
    }

    @Override
    public Document getDocument( File f ) throws IOException {
        Document doc = new Document();
        MechanismParseResult mpr = getParser().getParseResult();

        fillDocumentCommonStuff( doc, mpr );

        doc.add( new Field( CSConstantsLucene.FIELD_DESCRIPTION, mpr.getDescription(), Field.Store.YES, Field.Index.NOT_ANALYZED ) );

        return doc;
    }

    @Override
    public String getDataPath() {
        return "/docs/mechanisms";
    }

    @Override
    public MechanismsParser getParser() {
        return (MechanismsParser) super.getParser();
    }

    @Override
    public CMParser getNewParser( File f ) throws FileNotFoundException, XMLStreamException {
        return new MechanismsParser( f );
    }

}
